package medium;

import java.util.HashSet;

/**
 * @author admin
 * 3. 无重复字符的最长子串
 * 解题思路：滑动窗口思想，求以每个字符开始最长的子串
 */
public class LeeCode03 {

    public int lengthOfLongestSubstring(String s) {
        if (s.length() == 0){
            return 0;
        }
        if (s.length() == 1){
            return 1;
        }
        HashSet<Character> set = new HashSet<>();
        int res = 0;
        for (int i = 0 ;i<s.length();i++){
            for (int j = i ; j<s.length();j++){
                char c = s.charAt(j);
                if (!set.contains(c)){
                    set.add(c);
                }else {
                    if (set.size() > res){
                        res = set.size();
                    }
                    set.clear();
                    break;
                }
            }
        }
        return res;



    }

    public static void main(String[] args) {
        System.out.println(new LeeCode03().lengthOfLongestSubstring("jbpnbwwd"));
    }
}
